class MaxConsecutiveAnswers:
    #   answerKey = "TFFT", k = 1  可以将最前面的 'T' 换成 'F' ，得到 answerKey = "FFFT"
    #  滑动窗口, 字符为 'T' sum数减1, sum > k 则 left右移 保证窗口内 'F'最多为k个, 计算窗口内元素最大个数即可
    def maxConsecutiveAnswers(self, answerKey: str, k: int) -> int:
        def maxConsecutiveChar(ch: str) -> int:
            ans, left, sum = 0, 0, 0
            for right in range(len(answerKey)):
                sum += answerKey[right] != ch
                while sum > k:
                    sum -= answerKey[left] != ch
                    left +=1
                ans = max(ans, right - left + 1)
            return ans
        return max(maxConsecutiveChar('T'), maxConsecutiveChar('F'))
